﻿using Microsoft.Extensions.Options;


namespace OptinMonitorTest
{
    public class MonitorService
    {
        private readonly IOptionsMonitor<MyOptions> options;

        public MonitorService(IOptionsMonitor<MyOptions> options)
        {
            this.options = options;
            this.options.OnChange((opt, name) =>
            {
                Console.WriteLine("参数改变:{0},name:{1}", opt.ToString(), name);
            });
        }

        public void show() {
            Console.WriteLine("Monitor:begin---");
            Console.WriteLine(options.CurrentValue.ToString());
            Console.ReadKey();
            Console.WriteLine(options.CurrentValue.ToString());
            Console.WriteLine("Monitor:end----");
        }
    }
}
